#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
	int n, m, k;
	cin >> n >> m >> k;
	int x = n * m / k;
	vector<int> a;
	for (int i = 0; i < x; i++) for (int j = 1; j <= k; j++) a.push_back(j);
	if (m % k == 0)
	{
		vector<int> b(m);
		for (int i = 1; i <= m; i++) b[i - 1] = ((i - 1) % k) + 1;
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++) cout << b[j] << ' ';
			cout << endl;
			int x = b[0];
			b.erase(b.begin());
			b.push_back(x);
		}
	}
	else
	{
		int index = 0;
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
				cout << a[index++] << ' ';
			cout << endl;
		}
	}
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}